package com.libgdxbar.pvzlikegame.objects.bullets;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Shape2D;
import com.badlogic.gdx.utils.Pool;
import com.libgdxbar.pvzlikegame.entities.RectMoveableCollisableEntity;

import org.libgdxbar.projects.interfaces.renderer.IShapeRender;

public class SampleBullet extends RectMoveableCollisableEntity implements IShapeRender, Pool.Poolable {
	final float halfDiagonalLength = (float) (Math.sqrt(2.0) / 2.0);
	boolean isActive = false;

	public SampleBullet() {
		super(0, 0, 20, 20);
	}

	public void init(float x, float y, float velocityX, float velocityY) {
		getMoveableEntity().setPosition(x, y);
		getMoveableEntity().setVelocity(velocityX, velocityY);
		isActive = true;
	}

	@Override
	public void run(float delta) {
		if (!isActive) return;
		super.run(delta);
	}

	@Override
	public void render(ShapeRenderer renderer) {
		if (!isActive) return;
		renderer.setColor(Color.GREEN);
		renderer.set(ShapeRenderer.ShapeType.Filled);
		renderer.circle(getRect().x + getWidth() / 2, getRect().y + getHeight() / 2, getWidth() * halfDiagonalLength);
		renderer.setColor(Color.RED);
		renderer.set(ShapeRenderer.ShapeType.Line);
		renderer.rect(getRect().x, getRect().y, getWidth(), getHeight());
	}

	@Override
	public boolean overlap(Shape2D shape) {
		if (!isActive) return false;
		return super.overlap(shape);
	}

	@Override
	public void reset() {
		isActive = false;
	}
}
